<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<br><br>

<form class="layui-form" action="" lay-filter="item" style="width: 500px;margin: 0 auto;">
    <input type="hidden" name="id" readonly value="${item.id!''}">


    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>模块名</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="text" name="title"
                   lay-verify="required" placeholder="请输入模块名"
                   autocomplete="off" class="layui-input" value="${item.title!''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>app版本号</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="number" name="version"
                   lay-verify="required" placeholder="app版本号"
                   autocomplete="off" class="layui-input" value="${item.version!'10'}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>余额大于可见（分）</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="number" name="lookMoney"
                   lay-verify="required" placeholder="余额大于可见（分）"
                   autocomplete="off" class="layui-input" value="${item.lookMoney!'0'}">
        </div>
    </div>

    <input type="hidden" name="picture" placeholder="请输入图标"
           autocomplete="off" class="layui-input" value="${item.picture!''}">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 135px;padding-left: 0;text-align: right">图片上传:</label>
        <div class="layui-input-block" style="width: 340px;margin-left: 135px">
            <button type="button" class="layui-btn" id="test1" style="margin-top: -20px">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <img src="${item.picture!''}" id="icon" width="auto" height="80px">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>排序</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="text" name="sort"
                   lay-verify="required" placeholder="请输入排序"
                   autocomplete="off" class="layui-input" value="${item.sort!''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>打开类型</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="text" name="type"
                   lay-verify="required" placeholder="请输入排序"
                   autocomplete="off" class="layui-input" value="${item.type!''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>跳转类型</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="text" name="newhandCategory"
                   lay-verify="required" placeholder="请输入排序"
                   autocomplete="off" class="layui-input" value="${item.newhandCategory!''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>路径</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="text" name="url"
                   lay-verify="required" placeholder="请输入路径"
                   autocomplete="off" class="layui-input" value="${item.url!''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>说明</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="text" name="msg"
                   lay-verify="required" placeholder="请输入说明"
                   autocomplete="off" class="layui-input" value="${item.msg!''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>屏蔽渠道</label>
        <div class="layui-input-block" style="width: 250px">
            <input type="text" name="brand"
                   lay-verify="required" placeholder="多个渠道用#号隔开"
                   autocomplete="off" class="layui-input" value="${item.brand!'ALL'}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px">选择任务对应的类型</label>
        <div class="layui-input-block" style="width: 250px">
            <div style="width: 250px;">
                <select name="myType" id="myType" lay-verify="">
                    <option value=0 <#if item.myType == 0>selected</#if>>其他</option>
                    <option value=1 <#if item.myType == 1>selected</#if>>手游任务</option>
                    <option value=2 <#if item.myType == 2>selected</#if>>默认推荐</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px">选择父模块</label>
        <div class="layui-input-block" style="width: 250px">
            <div style="width: 250px;">
                <select name="parentId" id="parentId" lay-verify="">
                    <option value=1 <#if item.parentId == 1>selected</#if>>顶部模块</option>
                    <option value=2 <#if item.parentId == 2>selected</#if>>任务模块</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 70px"><span class="c-red">*</span>是否启用</label>
        <div class="layui-input-block">

            <#if item.enable gt 0 && item.enable??>
                <input type="radio" name="enable" value=1 title="是" checked>
                <input type="radio" name="enable" value=0 title="否">
            <#elseif item.enable == 0 && item.enable??>
                <input type="radio" name="enable" value=1 title="是">
                <input type="radio" name="enable" value=0 title="否" checked>
            <#else >
                <input type="radio" name="enable" value=1 title="是" checked>
                <input type="radio" name="enable" value=0 title="否">
            </#if>
        </div>
    </div>
    <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
        <select name="lookCategory" id="lookCategory" lay-verify="" style="width: 300px">
            <option value="">不设置</option>
            <#list looklist as list>
                <option value="${list.category}"  <#if item.lookCategory??><#if item.lookCategory==list.category>selected</#if > </#if> >${list.category}</option>
            </#list>
        </select>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formUpdate">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script>
    layui.use('upload', function () {
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            , url: '/picture/qiniu/upload' //上传接口
            , acceptMime: 'image/jpg, image/png'
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                i = ityzl_SHOW_LOAD_LAYER();
            }
            , done: function (res) {
                if (res.success) {
                    layer.msg(res.message, {icon: 1})
                    var form = layui.form;
                    form.val("item", {
                        "picture": res.data
                    })
                    $("#icon").attr("src", res.data);
                } else {
                    layer.msg(res.message, {icon: 2})
                }
                ityzl_CLOSE_LOAD_LAYER(i);
                //上传完毕回调
                //do something （比如将res返回的图片链接保存到表单的隐藏域）
                //  layer.msg(res.msg);
                ityzl_SHOW_TIP_LAYER();

            }
            , error: function () {
                //请求异常回调
                ityzl_CLOSE_LOAD_LAYER(i);
                layer.msg("上传失败请重试！")
            }
        });
    });

    function ityzl_SHOW_LOAD_LAYER() {
        return layer.msg('努力上传中...', {
            icon: 16,
            shade: [0.5, '#f5f5f5'],
            scrollbar: false,
            offset: '0px',
            time: 100000
        });
    }

    function ityzl_CLOSE_LOAD_LAYER(index) {
        layer.close(index);
    }

    function ityzl_SHOW_TIP_LAYER() {
        layer.msg('恭喜您，上传完成！', {time: 1000, offset: '10px'});
    }

    $(document).ready(function () {
        layui.use('form', function () {

            var form = layui.form;
            form.render();
            form.on('submit(formUpdate)', function (data) {
                $.ajax({
                    url: "/app/config/redis/app/edit",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data: data.field,    //参数值,键值对
                    type: "post",   //请求方式
                    beforeSend: function () {
                        //请求前的处理
                    },
                    success: function (req) {
                        //请求成功时处理
                        if (req.success) {
                            parent.showmsg(req.message);
                            parent.search();
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭

                        } else {
                            layer.msg(req.message)
                        }
                    },
                    complete: function () {
                        //请求完成的处理
                    },
                    error: function () {
                        //请求出错处理
                        layer.msg("请重试！若在失败请联系管理员")
                    }
                });

                return false;
            });
        });
    });

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>